package ar.edu.uba.fi.jmit.monitorengine.backend.server;

import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;

import ar.edu.uba.fi.jmit.monitorengine.MonitorEngineTestCase;
import ar.edu.uba.fi.jmit.monitorengine.backend.shared.dto.VisualizerDTO;
import ar.edu.uba.fi.jmit.monitorengine.parser.ParsersManager;

public class VisualizersServiceTestCase extends MonitorEngineTestCase {
	
	public void testGetLoadedVisualizers() {
		VisualizersServiceImpl service = new VisualizersServiceImpl();
		ParsersManager.loadConfigurationsDefault();
		LinkedList<VisualizerDTO> visualizers = service.getLoadedVisualizers();
		assertEquals(3, visualizers.size());
		Collections.sort(visualizers, new Comparator<VisualizerDTO>() {
			@Override
			public int compare(VisualizerDTO o1, VisualizerDTO o2) {
				return o1.getName().compareTo(o2.getName());
			}
		});
		assertEquals("Visualizer1", visualizers.get(0).getName());
		assertEquals("Visualizer2", visualizers.get(1).getName());
		assertEquals("Visualizer3", visualizers.get(2).getName());
		
		assertEquals(2, visualizers.get(0).getMonitors().size());
		assertEquals(1, visualizers.get(1).getMonitors().size());
		assertEquals(1, visualizers.get(2).getMonitors().size());
		
		assertEquals("testInvocationCounter5", visualizers.get(0).getMonitors().get(0));
		assertEquals("PointTestObjectCounter4", visualizers.get(0).getMonitors().get(1));
		assertEquals("testInvocationCounter3", visualizers.get(1).getMonitors().get(0));
		assertEquals("valorYPointTestFieldValue3", visualizers.get(2).getMonitors().get(0));
		
		assertEquals("http://10.0.0.4:8080/visualizer1", visualizers.get(0).getConnectionUrl());
		assertEquals("http://10.0.0.3:8080/visualizer2", visualizers.get(1).getConnectionUrl());
		assertEquals("http://10.0.0.2:8080/visualizer3", visualizers.get(2).getConnectionUrl());
		
	}

}
